/****************************************************************************
*                                                                           *
* sensor.h										                            *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/
#pragma once

#if !defined(__SENSOR_H)
#define __SENSOR_H

/****************************************************************************
* Includes										                            *
****************************************************************************/
#include "../../common/defs.h"
#include "../graph/graphnode.h"
#include <string>
#include <QString>
#include <QPoint>

/****************************************************************************
* CMaterial										                            *
****************************************************************************/
class CSensor : public CGraphNode
{
public :
	/****************************************************************************
	* Constraction/Destruction						                            *
	****************************************************************************/
	CSensor(int nFieldWidth, int nFieldHeight, int nPosX, int nPosY, QString strName); 
	~CSensor();

	static unsigned int makeUniqueID(int nPosX, int nPosY);

	/****************************************************************************
	* Public workers								                            *
	****************************************************************************/
	void updateField(const unsigned char *rgnbyFieldData, int nFieldWidth, int nFieldHeight);
	std::string stdStringName() const; 
	inline void setFieldUpdated(bool bUpdated) { m_bFieldUpdated = bUpdated; }
	inline const unsigned char* getField() const 
		{ assert(true == m_bFieldUpdated); assert(m_rgnbyField != NULL); return m_rgnbyField; }
	inline bool isFieldUpdated() const { return m_bFieldUpdated; }
	inline void setFieldAt(int nPosX, int nPosY, unsigned char byValue) 
	{ 
		assert(m_rgnbyField != NULL); 
		assert(nPosX >= 0 && nPosX < m_nFieldWidth);
		assert(nPosY >= 0 && nPosY < m_nFieldHeight);
		if (NULL != m_rgnbyField && 
			nPosX >= 0 && nPosX < m_nFieldWidth && 
			nPosY >= 0 && nPosY < m_nFieldHeight)
			m_rgnbyField[nPosY * m_nFieldWidth + nPosX] = byValue; 
	}
	inline void setFieldAt(QPoint& qPoint, unsigned char byValue) 
	{ 
		assert(m_rgnbyField != NULL); 
		assert(qPoint.x() >= 0 && qPoint.x() < m_nFieldWidth);
		assert(qPoint.y() >= 0 && qPoint.y() < m_nFieldHeight);
		if (NULL != m_rgnbyField && 
			qPoint.x() >= 0 && qPoint.x() < m_nFieldWidth && 
			qPoint.y() >= 0 && qPoint.y() < m_nFieldHeight)
			m_rgnbyField[qPoint.y() * m_nFieldWidth + qPoint.x()] = byValue; 
	}
	inline unsigned char getFieldAt(int nPosX, int nPosY)
	{ 
		assert(m_rgnbyField != NULL);  
		assert(nPosX >= 0 && nPosX < m_nFieldWidth);
		assert(nPosY >= 0 && nPosY < m_nFieldHeight);
		assert(true == m_bFieldUpdated);  
		if (NULL != m_rgnbyField && true == m_bFieldUpdated && 
			nPosX >= 0 && nPosX < m_nFieldWidth && 
			nPosY >= 0 && nPosY < m_nFieldHeight)
			return m_rgnbyField[nPosY * m_nFieldWidth + nPosX];
		return 0;
	}
	inline int x() const { return m_nPosX; } 
	inline int y() const { return m_nPosY; }  
	inline QPoint point() const { return QPoint(m_nPosX, m_nPosY); }  
	inline unsigned int getUniqueID() const { return m_nUniqueID; } 
	inline QString name() const { return m_strName; }
	inline int fieldWidth() const { return m_nFieldWidth; }   
	inline int fieldHeight() const { return m_nFieldHeight; }
	
	inline int outputPower() const { return m_nOutputPower; }
	inline int sensitivity() const { return m_nSensitivity; }

	inline float getRefField() const { return m_fltRefField; }
	inline void setRefField(float fltRefField) { m_fltRefField = fltRefField; }
	/****************************************************************************
	* Public data																*
	****************************************************************************/

protected: 
	/****************************************************************************
	* Protected data								                            *
	****************************************************************************/
	// sensor's unique identifier
	unsigned int		m_nUniqueID;
	// output power, dBm
	int		m_nOutputPower;		
	// referance value of the field
	float	m_fltRefField;		
	// sensitivity, dBm	
	int		m_nSensitivity;		
	// sensor's name 
	QString				m_strName;
	// field width 
	int m_nFieldWidth;
	// field height 
	int m_nFieldHeight;
	int m_nPosX;
	int m_nPosY;
	// field
	unsigned char *m_rgnbyField;

private:
	bool m_bFieldUpdated;
	CSensor(const CSensor& sensor);
};

#endif /* __SENSOR_H */
/****************************************************************************
* End of file																*
****************************************************************************/